package club.banyuan.hrms.util;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbC3P0Util {
    private static String driver = PropUtil.getProp("jdbc.driver");
    private static String url = PropUtil.getProp("jdbc.url");
    private static String username = PropUtil.getProp("jdbc.username");
    private static String password = PropUtil.getProp("jdbc.password");
    private static ComboPooledDataSource dataSource = null;

    static {
        try {
            // 连接池
            dataSource = new ComboPooledDataSource();
            dataSource.setDriverClass(driver);
            dataSource.setJdbcUrl(url);
            dataSource.setUser(username);
            dataSource.setPassword(password);
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
}
